class Acceleration2 extends egret.DisplayObjectContainer {
    public ball:Ball
    public vx:number = 0
    public ax:number = 0

    public constructor() {
        super()
        this.addEventListener( egret.Event.ADDED_TO_STAGE, this.onAddToStage, this)
    }

    private onAddToStage(event:egret.Event) {
        this.ball = new Ball()
        this.addChild(this.ball)
        this.ball.x = this.stage.stageWidth/2
        this.ball.y = this.stage.stageHeight/2
        this.stage.addEventListener(egret.TouchEvent.TOUCH_BEGIN, (evt:egret.TouchEvent) => {
            if (evt.localX < this.stage.stageWidth/2) {
                this.ax = -0.2
            } else {
                this.ax = 0.2
            }
        }, this)
        this.stage.addEventListener(egret.TouchEvent.TOUCH_END, (evt:egret.TouchEvent) => {
            this.ax = 0
        }, this)

        this.addEventListener(egret.Event.ENTER_FRAME, this.onEnterFrame, this)
    }

    private onEnterFrame(event:egret.Event) {
        this.vx += this.ax
        this.ball.x += this.vx
    }
}